package cn.wokoba.dao.dao;

import cn.wokoba.dao.dao.po.GroupBuyOrderList;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface IGroupBuyOrderListDao extends BaseMapper<GroupBuyOrderList> {


    @Select("""
                select user_id, team_id, order_id, activity_id, start_time,
                    end_time, goods_id, source, channel, original_price, deduction_price, status
                    from group_buy_order_list
                    where out_trade_no = #{outTradeNo} and user_id = #{userId} and status = 0\
            """)
    GroupBuyOrderList queryGroupBuyOrderRecordByOutTradeNo(GroupBuyOrderList groupBuyOrderListReq);

    @Update("""
                    update group_buy_order_list
                           set status = 1, out_trade_time = #{outTradeTime}, update_time = now()
                           where out_trade_no = #{outTradeNo} and user_id = #{userId}
            """)
    int updateOrderStatus2COMPLETE(GroupBuyOrderList groupBuyOrderListReq);

    @Select(" select out_trade_no from group_buy_order_list where team_id = #{teamId} and status = 1")
    List<String> queryGroupBuyCompleteOrderOutTradeNoListByTeamId(String teamId);

    @Update(" update group_buy_order_list set status=2,update_time=now() where order_id=#{orderId} and user_id=#{userId} ")
    void updateOrderStatus2Refund(GroupBuyOrderList groupBuyOrderListReq);
}
